﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KendoMvcUI.Core;
using KendoMvcUI.Common;
using System.Web.Mvc;

namespace KendoMvcUI.UI
{
    public class TimePicker:KendoUIBase
    {
        public TimePicker(KendoUIControlSettings settings,ViewContext context,IViewDataContainer container)
            :base(settings,context,container)
        { }

        public override string RenderHtml()
        {
            return "<input id=\"{0}\"/>".Formator(Settings.Id);
        }
    }
    public class TimePickerSettings : KendoUIControlSettings
    {
        public TimePickerSettings()
            : base("kendoTimePicker")
        { }
        [PropertySetting(IsIngoreForJavaScript=true)]
        public Action<AnimationSettings> Animation { get; set; }
        public string Culture { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript = true)]
        public Action<List<DateTime>> Dates { get; set; }
        /// <summary>
        /// default: "h:mm tt"
        /// </summary>
        public string Format { get; set; }
        public int? Interval { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public DateTime? Max { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public DateTime? Min { get; set; }
        /// <summary>
        /// Specifies the formats, which are used to parse the value set with the 
        /// value method or by direct input. If not set the value of the options.
        /// format will be used. Note that value of the format option is always used.
        /// Order of the provided parse formats is important and it should from stricter to less strict.
        /// </summary>
        [PropertySetting(IsIngoreForJavaScript = true)]
        public List<string> ParseFormats { get; set; }
        [PropertySetting(IsIngoreForJavaScript = true)]
        public DateTime? Value { get; set; }
        #region 事件
        public string On_Change { get; set; }
        public string On_Close { get; set; }
        public string On_Open { get; set; }
        #endregion
        public override string ToJsSettings()
        {
            string jsScript = base.ToJsSettings();
            if (!jsScript.EndsWith(","))
                jsScript += ",";
            if(Animation!=null)
            {
                AnimationSettings animation = new AnimationSettings();
                Animation(animation);
                jsScript += animation.ToString() + ",";
            }
            if (Dates != null)
            {
                List<DateTime> dates = new List<DateTime>();
                Dates(dates);
                string datesStr = "";
                foreach (var date in dates)
                {
                    datesStr += string.Format("new Date({0},{1},{2},{3},{4},{5})",
                        date.Year, date.Month, date.Day, date.Hour, date.Minute, date.Second) + ",";
                }
                jsScript += string.Format("[{0}]", datesStr.TrimEnd(',')) + ",";
            }
            if (Max.HasValue)
            {
                jsScript += string.Format("new Date({0},{1},{2},{3},{4},{5})",
                    Max.Value.Year, Max.Value.Month, Max.Value.Day, Max.Value.Hour, Max.Value.Minute,
                    Max.Value.Second) + ",";
            }
            if (Min.HasValue)
            {
                jsScript += string.Format("new Date({0},{1},{2},{3},{4},{5})",
                    Min.Value.Year, Min.Value.Month, Min.Value.Day, Min.Value.Hour, Min.Value.Minute,
                    Min.Value.Second) + ",";
            }
            if (Value.HasValue)
            {
                jsScript += string.Format("new Date({0},{1},{2},{3},{4},{5})",
                    Value.Value.Year, Value.Value.Month, Value.Value.Day, Value.Value.Hour, Value.Value.Minute,
                    Value.Value.Second) + ",";
            }
            if (ParseFormats != null)
            {

            }
            return jsScript;
        }
    }
}
